//
//  YMPurchaseOrderDetailVC.swift
//  NewVersionDemo
//
//  Created by zeng on 2018/3/19.
//  Copyright © 2018年 youmy. All rights reserved.
//  我的购买记录-订单详情

import UIKit

fileprivate let kCellId = "kCellId"

class YMPurchaseOrderDetailVC: UIViewController {

    @IBOutlet weak var tableView: UITableView!
    
    let datas = [["订单编号","订单金额","下单时间"],["联系人","联系地址","联系电话"],["商品型号","成色","网络制式","姿色","内存","碎屏保险"]]
    
    fileprivate lazy var hearderView = YMPurchaseOrderDetailHeaderView.nibView()
    override func viewDidLoad() {
        super.viewDidLoad()

//        tableView.tableHeaderView = hearderView
        tableView.separatorStyle = .none
        tableView.backgroundColor = ym_label_bg_color
        tableView.dataSource = self
        tableView.delegate = self
        
        tableView.register(UINib.init(nibName: "YMPurchaseOrderDetailCell", bundle: nil), forCellReuseIdentifier: kCellId)
    }

}

extension YMPurchaseOrderDetailVC: UITableViewDataSource, UITableViewDelegate{
    func numberOfSections(in tableView: UITableView) -> Int {
        return datas.count
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        let arr = datas[section]
        return arr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: kCellId, for: indexPath) as! YMPurchaseOrderDetailCell
        let arr = datas[indexPath.section]
        let string = arr[indexPath.row]
        if string == "联系地址" {
            cell.detailTitleLbl.text = "广东省深圳市南山区高新南一道中科大厦18F广东省深圳市南山区高新南一道中科大厦18F"
        }else{
            cell.titleLbl.text = string
        }
        return cell
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return UITableViewAutomaticDimension
    }
    
    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return section > 0 ? 5.0 : 0.001
    }
    
    func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
        return 10
    }
    
    func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 5))
        view.backgroundColor = .white
        return view
    }
}
